<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test.js"></script>
<script src="../resources/common.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>

<script>
description("Test that HKDF does not support methods it should not support.");

jsTestIsAsync = true;

kHkdfKey = "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b";

kHkdfAlgorithm = {
    name: "HKDF",
    hash: "SHA-256",
    salt: new Uint8Array(),
    info: new Uint8Array()
};

var extractable = false;
Promise.resolve(null).then(function(result) {
    // Set up the test by creating an HKDF key.
    return crypto.subtle.importKey("raw", hexStringToUint8Array(kHkdfKey), {name: "HKDF"}, extractable, ['deriveKey', 'deriveBits']);
}).then(function(result) {
    baseKey = result;

    debug("Derive 0 bits from the HKDF key");
    return crypto.subtle.deriveBits(kHkdfAlgorithm, baseKey, 0);
}).then(function(result) {
    derivedBits = result;

    shouldBe("derivedBits.byteLength", "0");

    debug("Derive 8 bits from the HKDF key");
    return crypto.subtle.deriveBits(kHkdfAlgorithm, baseKey, 8);
}).then(function(result) {
    derivedBits = new DataView(result);

    shouldBe("derivedBits.byteLength", "1");
    shouldBe("derivedBits.getUint8(0)", "141");
}).then(finishJSTest, failAndFinishJSTest);

</script>

</body>
</html>
